package com.pug.service.advice;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pug.mapper.advice.AdviceMapper;
import com.pug.pojo.Advice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/4/27$ 21:05$
 */
@Service
@Slf4j
public class AdviceServiceImpl extends ServiceImpl<AdviceMapper, Advice> implements IAdviceService  {
    //查询公告
    @Override
    public List<Advice> findIndexAdvice(Integer pageNo, Integer pageSize) {
        Page<Advice> page=new Page<>(pageNo,pageSize);
        //设置分页条件
        QueryWrapper<Advice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("status",1);
        queryWrapper.orderByAsc("sorted");
        Page<Advice> page1 = this.baseMapper.selectPage(page, queryWrapper);
        List<Advice> records = page1.getRecords();
        if(records==null) return new LinkedList<>();
        return records;
    }

/**
     * 查询公告
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
//    @Override
//    public List<Advice> findIndexAdvice(Integer pageNo, Integer pageSize) {
//        // 1: 设置分页
//        Page<Advice> page = new Page<>(pageNo, pageSize);
//        // 2 :设置条件
//        LambdaQueryWrapper<Advice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(Advice::getStatus, 1);
//        lambdaQueryWrapper.orderByAsc(Advice::getSorted);
//
//        Page<Advice> advicePage = this.page(page, lambdaQueryWrapper);
//        List<Advice> records = advicePage.getRecords();
//        if (CollectionUtils.isEmpty(records)) {
//            return new ArrayList<>();
//        }
//        return records;
//    }

}
